package exercise16;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Test5 extends JFrame {
	public Test5() {
		add(new Fan1());
	}

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		Test5 frame = new Test5();
		frame.setSize(250, 300);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}

class Fan1 extends JPanel{
	private int angle = 100; 
	private int direction = 1; 
	private int speed = 10; 
	protected Timer timer = new Timer(speed,new TimerListener()); 
	public Fan1(){
		timer.start(); 
		} 
	
	class TimerListener implements ActionListener{ 
		public void actionPerformed(ActionEvent e){
			repaint(); 
			} 
		}
	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		int xCenter = getWidth()/2;
		int yCenter = getHeight()/2; 
		int Fan1Radius = (int)(Math.min(getWidth(), getHeight())*0.4); 
		int bladeLength = (int)(Fan1Radius*0.9);
		angle = (angle+direction)%360; 
		g.setColor(Color.BLACK); 
		g.drawOval(xCenter-Fan1Radius, yCenter-Fan1Radius, Fan1Radius*2, Fan1Radius*2);
		g.setColor(Color.RED);
		g.fillArc(xCenter-bladeLength, yCenter-bladeLength, bladeLength*2, bladeLength*2, angle, 30);
		g.fillArc(xCenter-bladeLength, yCenter-bladeLength, bladeLength*2, bladeLength*2, angle+90, 30);
		g.fillArc(xCenter-bladeLength, yCenter-bladeLength, bladeLength*2, bladeLength*2, angle+180, 30);
		g.fillArc(xCenter-bladeLength, yCenter-bladeLength, bladeLength*2, bladeLength*2, angle+270, 30); 
		} }
		
		
		
		
		
		
		
		
		
		
		
		
		